<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.sinodata.bsm.center.purview.FunctionConstants"%>
<%@page import="com.sinodata.bsm.center.purview.UserFunctionValidate"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>dimension-config-common</title>
		<%@ include file="../include/common.jsp"%>
		<%@ include file="../include/jbox.jsp"%>
		<%@ include file="../include/table.jsp"%>
		<script type="text/javascript">
	    function addStyle(){
			$("#urlSpan").css({"display":"none"});
			var oInput = document.getElementById("url");
			oInput.focus();
		}
		function delStyle(){
			if($("#url").val() == ''){
				$("#urlSpan").css({"display":""});
			}
		}
		function cancelAllCheck(){
		   $("#dt_check_all").removeAttr("checked");
	    }
	    //全选和取消全选
	    function allClick(isSigle)
	    {
	    	if(isSigle!=1) //如果是单选就不支持全选
  	    	{
  	    		var dt_check_all = $('#dt_check_all').attr("checked");
	  	    	var allCheckbox = $("input[name='dt_check']");
	  	    	if(dt_check_all)
	  	    	{
	  	    		
	  	    		allCheckbox.attr("checked",allCheckbox);  //全选
	  	    		$('#depmtList tbody tr').addClass('row_selected');  //背景色全选
	  	    	}else
	  	    	{
	  	    		allCheckbox.attr("checked",false);   //取消全选
	  	    		$('#depmtList tbody tr').removeClass('row_selected');  //背景色取消
	  	    	}
  	    	}
	    }
	    function add() {
		    var url ="iframe:config/dimension-config!add.action?dimensionTypeId="+'${dimensionType.id}';
		    var opt = { title: "维度添加",width:560,height:250,buttons: {}};
		
		    getTopWin(window).openjBox(url,opt,'dimension-config-common',window);
	    }
	   function search(){
	       var oTable=	$('#depmtList').dataTable();
	       oTable.fnPageChange("first",true);
       }
	   //删除某个数据
	   function deleteOne(id){
		var submit = function (v, h, f) {
		    if (v == 'ok') {
		    	$.ajax({
		    		type : "POST",
		    		url : "${pageContext.request.contextPath}/config/dimension-config!delete.action", //请求的action
		    		data : {ids:id}, //传的参数
		    		dataType : 'json',
		    		success : function(data) { //结果
		    			if(data == true){
							window.setTimeout(function () { $.jBox.tip('删除成功。', 'success'); }, 100);
		    			}else{
		    				getTopWin(window).getMessageBox().alert("此条数据已经删除","提示");
		    			}
						datagrid();
		    		}
		    	});
		    }
		    else if (v == 'cancel') {
		    }
		    return true; //close
		};
		getTopWin(window).jBox.confirm("确定要删除数据吗？", "提示", submit);
	 } 	//得到当前选中的
	 function fnGetSelected() {   
			var selections = $('#depmtList tr.row_selected');
		    return selections;
	 }
  function edit(id){
	$.ajax({
  		type : "POST",
  		url : "${pageContext.request.contextPath}/config/dimension-config!checkDeleted.action", //请求的action
  		data : {id:id}, //传的参数
  		dataType : 'json',
  		success : function(data) { //结果
  			if(data.flag == true){
  			var url ="iframe:config/dimension-config!input.action?id="+id;
  			var opt = { title: "维度修改",width:560,height:200,buttons: {}};
  				getTopWin(window).openjBox(url,opt,'dimension-config-update',window);
  			}else{
  				getTopWin(window).getMessageBox().alert("此条数据已经删除","提示");
  				datagrid();
  			}
  		}
  	});
}

	 //批量删除
	 function batchDelete(){
		var rows = fnGetSelected();
		if(rows.length>0){
			var submit = function (v, h, f) {
			    if (v == 'ok') {
			        var mydata = {};
					mydata.Ids = new Array(rows.length);
					var oTable =$('#depmtList').dataTable();
					for(var i = 0 ; i<rows.length;i++){
						var aData = oTable.fnGetData(rows[i]);
						mydata.Ids[i] = aData.id;
					}
					$.ajax({
						type : "POST",
						url : "${pageContext.request.contextPath}/config/dimension-config!delete.action", //请求的action
						data : jQuery.param(mydata,true), //传的参数
						dataType : 'json',
						success : function(data) { //结果
							if(data == true){
								window.setTimeout(function () { $.jBox.tip('删除成功。', 'success'); }, 100);
			    			}else{
			    				getTopWin(window).getMessageBox().alert("包含已经删除的配置,请重新选择","提示");
			    			}
							cancelAllCheck();
							datagrid();
						}
					});
			    }
			    else if (v == 'cancel') {		       
			    }
			    return true; //close
			};
			getTopWin(window).jBox.confirm("确定要删除数据吗？", "提示", submit);
		}else{
			getTopWin(window).getMessageBox().alert("请选择一条数据","提示");
		}
	}
       function datagrid(){
			var oTable=	$('#depmtList').dataTable();
			oTable.fnPageChange("first",true);
	    }
	   $(function(){
	   $.ajaxSettings.traditional=true;
		$("#searchName").keyup(function(event){  
             if(event.keyCode == 13){  
                 search();
             }  
        }); 
	    //加载grid
	 var oTable=$('#depmtList').dataTable({
		"bProcessing": true, 
		"bServerSide": true,
		"sServerMethod": 'POST',
		"sAjaxSource":'${pageContext.request.contextPath}/config/dimension-config!list.action',
		"bPaginate": true,
		"bSort": true,
		"bFilter":false,
		"bJQueryUI":false,
		"sPaginationType": "full_numbers",
		"sDom":'rt <"bottom"flpi>',
		"iDisplayLength":20,
		"aLengthMenu": [[20, 50, 100], [20, 50,100]],
		"aoColumns":[
		<%if(UserFunctionValidate.sysFunctionValidate(FunctionConstants.SYSTEM_MANAGER)){%>
			{"mDataProp":"checkbox","bSortable": false},
			<%}%>
			{"mDataProp":"op","":"center","bSortable": false},
			{"mDataProp":"dimensionName"},
			{"mDataProp":"parentId"},
			{"mDataProp":"dimensionstate"},
			{"mDataProp":"id","bVisible":false}
		], 
		 "oLanguage": { 
		 				"sLengthMenu": "每页 _MENU_ 条",
		 		 		"sZeroRecords": "  ",
						"sInfo": "当前从 _START_ 到 _END_ 条,共 _TOTAL_ 条记录", 
						"sInfoEmpty": "没有找到记录",
						"oPaginate":{"sFirst":"首页","sPrevious":"上一页","sNext":"下一页","sLast":"尾页"}	
		},
	    "fnServerParams":function(aoData){
	    	var searchName = $('#searchName').val();
	    	aoData.push({'name':'dimensionTypeId','value':'${dimensionType.id}'})
	    	if(searchName!='')
	    	{
	    		aoData.push({'name':'searchName','value':searchName});
	    	}
	    }});
	    $('#depmtList tbody td :checkbox').live('click', function (e) {
			var nTr = $(this).parents('tr')[0]; 
		    	showDetailFlag = true;
			   if ($(nTr).hasClass('row_selected')) {
				  	$(nTr).removeClass('row_selected'); 
				  	cancelAllCheck();
			  }else
			  {
			  		$(nTr).addClass('row_selected'); 
			 }
			 if(!$(this).attr("checked")){
			 	$('#allCheck').attr("checked",false);
			 }
		});
		showDetailFlag = false;
	 });
		</script>
	</head>

	<body>
		<h2 class="title-h2" style="margin-top: 0;">
			<span><a onclick="javascript:history.go(-1)"><img
					src="${pageContext.request.contextPath}/style/default/bsm/images/arrow-down.gif" />
					</a>
			</span>${dimensionType.dimensionTypeName }类型维度管理
		</h2>
		<div class="toolbar" id="toolbar">

			<%
				if (UserFunctionValidate.sysFunctionValidate(FunctionConstants.SYSTEM_MANAGER)) {
			%>
			<a class="page_add" href="javascript:add();">新增</a>
			<a class="page_delete" href="javascript:batchDelete();">批量删除</a>
			<%
				}
			%>
			<div class="f-r-input" onclick="addStyle();">
				<input id="searchName" name="searchName" onfocus="addStyle();"
					onblur="delStyle();">
				<span id="urlSpan">搜索名称</span>
			</div>
		</div>

		<div>
			<table id="depmtList" width="100%" cellpadding="0" cellspacing="0"
				border="0" class="display">
				<thead>
					<tr>
						<%
							if (UserFunctionValidate
									.sysFunctionValidate(FunctionConstants.SYSTEM_MANAGER)) {
						%>
						<th width="22px">&nbsp;&nbsp;<input type='checkbox' name='dt_check_all' id="dt_check_all"
								onclick="allClick()" /></th>
						<th width="100px">操作</th>
						<%
							}
						%>
						<th width="150px">维度名称</th>
						<th width="150px">父级维度</th>
						<th width="50px">维度状态</th>
					</tr>
				</thead>
			</table>
		</div>
	</body>
</html>
